package routers

import (
	"github.com/dwbmio/go_ihome/pkg/setting"
	v1 "github.com/dwbmio/go_ihome/routers/api/v1"
	"github.com/gin-gonic/gin"
)

// InitRouter 初始化服务器路由
func InitRouter() *gin.Engine {
	r := gin.New()
	// 中间件
	r.Use(gin.Logger())
	r.Use(gin.Recovery())

	gin.SetMode(setting.RunMode)

	r.GET("/test_mqtt", func(c *gin.Context) {
		c.JSON(200, gin.H{
			"message": "test",
		})
	})

	// tag
	apiv1 := r.Group("/api/v1")
	{
		//获取标签列表
		apiv1.GET("/tags", v1.GetTags)
		//新建标签
		apiv1.POST("/tags", v1.AddTag)
		//更新指定标签
		apiv1.PUT("/tags/:id", v1.EditTag)
		//删除指定标签
		apiv1.DELETE("/tags/:id", v1.DeleteTag)
	}

	return r
}
